<?php

use frontend\modules\common\models\BaseParam;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\grid\GridView;
use yii\widgets\Pjax;
use yii\widgets\LinkPager;

/* @var $this yii\web\View */
/* @var $searchModel frontend\modules\resource\models\BranchSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '分馆列表';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="branch-index">

    <?php Pjax::begin(['id' => 'centerView']); ?>
    <div class="searchBody">
        <?php echo $this->render('_search', ['model' => $searchModel]); ?>
        <div class="addBtn">
            <?= Html::a('+新增', 'javascript:;', ['class' => 'btn btn-success create']) ?>
        </div>
    </div>
    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'columns' => [

            'id',
            'title',
            'color_value',
            'status' => [
                'attribute' => 'status',
                'value' => function ($model) {
                    return BaseParam::CodeHelper(BaseParam::$branchStatus, $model->status);
                }
            ],
            'show' => [
                'attribute' => 'show',
                'value' => function ($model) {
                    return BaseParam::CodeHelper(BaseParam::$branchShow, $model->show);
                }
            ],
            'start_time',
            'end_time',
            //'add_time',
            //'created_at',
            //'updated_at',
            //'deleted_at',

            //功能
            [
                'class' => 'frontend\modules\common\models\ActionJsColumn',
                'template' => '{update}{show}{users}{banner}{branch-classes}{branch-resource}{support}{top-support}{special}',
                'contentOptions' => ['style' => 'max-width: 480px;', 'width' => '480px'],
            ]
        ],
        'pager' => [
            'class' => LinkPager::className(),
            'firstPageLabel' => '首页',
            'prevPageLabel' => '《',
            'nextPageLabel' => '》',
            'lastPageLabel' => '尾页',
//            'goPageLabel' => true,
//            'totalPageLable' => '共x页',
//            'goButtonLable' => 'GO',
            'maxButtonCount' => 5,
            'hideOnSinglePage' => false,
        ]
    ]); ?>
    <?php Pjax::end(); ?>
</div>
<!--增删改 操作-->
<?php echo $this->render('../../../common/views/base/_column'); ?>
<script>
    <?php $this->beginBlock('js_ok_remove') ?>
    //显示隐藏
    $(document).on('click', '.show', function () {
        var id = $(this).closest('tr').data('key');

        $.ajax({
            type: "POST",
            url: '<?=Url::toRoute('show-hide')?>',
            data: {id: id},
            dataType: 'json'
        })
            .done(function (msg) {
                console.log(msg);
                if (msg['status'] == 200) {
                    layer.msg(msg['msg'], {icon: 1, time: 500}, function () {
                        $.pjax.reload({container: "#centerView"});
                    });
                } else {
                    layer.msg(msg['msg'], {icon: 2});
                }
            });
    });
    //banner管理
    $(document).on('click', '.banner', function () {
        var id = $(this).closest('tr').data('key');

        window.location.href = '/resource/banner?br_id=' + id;
    });
    //用户管理
    $(document).on('click', '.users', function () {
        var id = $(this).closest('tr').data('key');

        window.location.href = '/resource/branch-user?br_id=' + id;
    });
    //分类管理
    $(document).on('click', '.branch-classes', function () {
        var id = $(this).closest('tr').data('key');

        window.location.href = '/resource/branch-classes?br_id=' + id;
    });
    //资源管理
    $(document).on('click', '.branch-resource', function () {
        var id = $(this).closest('tr').data('key');
        window.location.href = '/resource/branch-resource?br_id=' + id;
    });
    //推荐资源
    $(document).on('click', '.support', function () {
        var id = $(this).closest('tr').data('key');

        window.location.href = '/resource/support/index?br_id=' + id;
    });
    //首页资源
    $(document).on('click', '.top-support', function () {
        var id = $(this).closest('tr').data('key');

        window.location.href = '/resource/support/top-index?br_id=' + id;
    });
    //专题列表
    $(document).on('click', '.special', function () {
        var id = $(this).closest('tr').data('key');

        window.location.href = '/resource/special/index?br_id=' + id;
    });

    <?php $this->endBlock() ?>
</script>
<?php $this->registerJs($this->blocks['js_ok_remove'], \yii\web\View::POS_END); ?>
